<?php

namespace App\Http\Models\Account;

use App\Http\Daos\Account\OrgAddressModel;
use App\Http\Daos\Account\OrganizationRelModel;
use App\Http\Daos\Account\SignTemplateEnableModel;
use App\Http\Daos\Account\TeamModel;
use App\Http\Daos\Account\VillageModel;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\OrganizationModel
 *
 * @property int $id
 * @property string $uid 唯一标识uid
 * @property string $parent_uid 上级机构uid
 * @property string $code 机构编号
 * @property string $name 机构名称
 * @property int $type 机构类型 1：行政机构 2：服务机构
 * @property string $province_code 所在省code
 * @property string $province_name 所在省名称
 * @property string $city_code 所在市code
 * @property string $city_name 所在市名称
 * @property string $area_code 所在区code
 * @property string $area_name 所在区名称
 * @property string $town_code 所在镇code
 * @property string $town_name 所在镇名称
 * @property string $village_uid 所在村uid
 * @property string $village_name 所在村名称
 * @property string $level_dic 医院等级字典类型code码
 * @property string $level_dict_code 医院等级字典码 （默认：1：省2：市 3：区，县 4：镇,街道 5：村）
 * @property string $level_type_dic 医院所属层级属性 字典类型code码
 * @property string $class_dict_code 医院所属层级属性字典码 1省、自治区级单位2.市、州级单位3.县、区、旗级单位4.街道、乡、镇级单位5.村委会、居委会级单位6.部级单位7.外地单位
 * @property int|null $grade 医院等级1 一级 2 二级
 * @property string|null $grade_name 医院等级名称
 * @property int|null $qualified_grade 医院资质等级1 甲等 2 乙等
 * @property string|null $qualified_grade_name 医院资质等级名称
 * @property string $phone 机构电话
 * @property string $link 机构联系人姓名
 * @property string $address 机构地址
 * @property string $photo 机构照片
 * @property string $describe 机构描述
 * @property string|null $longitude 经度
 * @property string|null $latitude 纬度
 * @property string $info 备注
 * @property int $sort 排序
 * @property int $state 是否启用 0：未启用 1：已启用
 * @property int $status 是否删除 0：已删除 1：正常
 * @property string $create_account_uid 创建用户uid
 * @property \Illuminate\Support\Carbon $create_time 创建时间
 * @property string $modify_account_uid 修改用户uid
 * @property \Illuminate\Support\Carbon $modify_time 创建时间
 * @property-read \App\Http\Daos\Account\OrganizationRelModel $organizationRel
 * @property-read \App\Http\Daos\Account\OrganizationModel $parentOrganization
 * @property-read \App\Http\Daos\Account\VillageModel $village
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Http\Daos\Account\TeamModel[] $teams
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereAreaCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereAreaName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereCityCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereCityName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereCreateAccountUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereCreateTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereDescribe($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereGrade($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereGradeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereInfo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLatitude($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLevelDictionaryCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLevelDictionaryTypeCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLevelTypeDictionaryCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLevelTypeDictionaryTypeCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLink($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLongitude($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereModifyAccountUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereModifyTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereParentUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel wherePhoto($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereProvinceCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereProvinceName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereQualifiedGrade($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereQualifiedGradeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereState($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereTownCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereTownName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereVillageName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereVillageUid($value)
 * @mixin \Eloquent
 * @property string $phonetic_code 机构拼音码（名称首字母）
 * @property string $level_dict 医院等级字典类型code码
 * @property string $class_dict 医院所属层级属性 字典类型code码
 * @property int $source 信息来源1本地添加2pad
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Http\Daos\Account\SignTemplateEnableModel[] $templateEnable
 * @property-read int|null $template_enable_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereClassDict($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereClassDictCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLevelDict($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereLevelDictCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel wherePhoneticCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereSource($value)
 * @property string $seal_photo 机构盖章
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Http\Daos\Account\OrganizationModel whereSealPhoto($value)
 * @property-read int|null $teams_count
 */
class OrganizationModel extends Model
{
    protected $table = 'organization';

    const CREATED_AT = 'create_time';

    const UPDATED_AT = 'modify_time';

    protected $guarded = [];

    public function organizationRel()
    {
        return $this->hasOne(OrganizationRelModel::class, 'uid', 'uid');
    }

    public function village()
    {
        return $this->hasOne(VillageModel::class, 'uid', 'village_uid')->where('status', 1);
    }

    public function parentOrganization()
    {
        return $this->hasOne(OrganizationModel::class, 'uid', 'parent_uid');
    }

    public function templateEnable()
    {
        return $this->hasMany(SignTemplateEnableModel::class, 'organization_uid', 'uid');
    }

    public function teams()
    {
        return $this->hasMany(TeamModel::class, 'organization_uid', 'uid')->where('status', 1);
    }

    public function orgAddress()
    {
        return $this->hasMany(OrgAddressModel::class, 'org_uid', 'uid');
    }
}
